<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use common\components\helpers\Fun;
use common\components\extenders\MenuManage;
use doumiaoduo\layer\LayerIframeWidget;
use doumiaoduo\layer\LayerAsset;
LayerAsset::register($this);

LayerIframeWidget::widget(['button'=>"['添加','取消']"]);


?>
<?php $form = ActiveForm::begin(['enableAjaxValidation' => true, 'enableClientValidation' => false, 'options' => ['class' => 'form-validate']]); ?>
<div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height" id="toolbar">
   <div>
       <div class="docs-main zx-mg">
           <table id="tablesaw" class="tablesaw table yx-table1 yx-table5 table-striped with-check"  data-tablesaw-mode="swipe" data-tablesaw-minimap >
               <thead>
               <tr class="yx-bgd2f6ec">
                    <th><?=\Yii::t('zhtfrontend','商品名称');?></th>
                    <th><?=\Yii::t('zhtfrontend','分类名称');?></th>
                    <th><?=\Yii::t('zhtfrontend','剩余人数');?></th>
                    <th><?=\Yii::t('zhtfrontend','上课时间');?></th>
                   <th><?=\Yii::t('zhtfrontend','查看');?></th>

                </thead>
             <?php foreach ($data as $m) {?>
               <tr id="main">
                   <td><?=$m['name']?></td>
                   <td><?=$m['cate_name']?></td>
                   <td><?=$m['mechanic_name']?></td>
                   <td><?=$m['store']?></td>
                   <td><?=$m['price']?></td>
                   <td><?=$m['class_time']?></td>
                   <td><?=$m['class_count']?></td>
                   <td>
                       <select name="discount_type[<?=$m['id']?>]" style="width: 120px">
                           <option value="0">请选择</option>
                           <option value="1" <?php if($m['discount_type'] == 1) { ?>selected <?php } ?>>按比例(%)</option>
                           <option value="2" <?php if($m['discount_type'] == 2) { ?>selected <?php } ?>>固定减额</option>
                       </select>

                   </td>
                   <td><input type="text" name="price_reduce[<?=$m['id']?>]" style="width: 50px" value="<?=$m['reduce']?>"></td>
                   <td></td>
               </tr>
             <?php } ?>
               <?php if(!empty($artModel)) { ?>
                   <tr>
                       <td><?=$artModel['title']?></td>
                       <td><?php
                            switch ($artModel['type']){
                                case 1:
                                    echo '益智';
                                    break;
                                case 2:
                                    echo '音乐';
                                    break;
                                default:
                                    echo '形体';
                                    break;
                            }
                           ?></td>
                       <td>豆苗朵</td>
                       <td><?=$artModel['max_count']?></td>
                       <td><?=$artModel['price']?></td>
                       <td><?=\common\components\helpers\Util::getWeek($artModel['class_day']).' '.$artModel['star_time'].'-'.$artModel['end_time']?></td>
                       <td><?=$artModel['class_count']?></td>
                       <td>
                           <select name="discount_type[<?=$artModel['id']?>]" style="width: 120px">
                               <option value="0">请选择</option>
                               <option value="1" <?php if($artModel['discount_type'] == 1) { ?>selected <?php } ?>>按比例(%)</option>
                               <option value="2" <?php if($artModel['discount_type'] == 2) { ?>selected <?php } ?>>固定减额</option>
                           </select>
                       </td>
                       <td><input type="text" name="price_reduce[<?=$artModel['id']?>]" style="width: 50px" value="<?=(int)$artModel['price_reduce']?>"></td>
                       <td><a class="btn yx-radius2 yx-d-card yx-bg94d5a2" data-url="<?=Fun::url(['goodsskill/viewgroup','id'=>$artModel['id']])?>" data-size="1000*600" data-name="查看" rel="dialog-show-iframe" >查看</a></td>
                   </tr>
               <?php } ?>
            </table>

        </div>
        <div style="margin: 10px">
            <span>
                <?=Html::dropDownList('art_id',null,$artList,['style'=>'padding:3px 5px; margin-right:20px','prompt' => '请选择艺教学','id'=>'artList'])?>
                <a class='yx-batch-settlement  yx-ml10 yx-radius2' id="confirm" >确认价格</a>
            </span>
        </div>
   </div>
    <table width="100%" class="table-form">
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['groupIds']; ?></th>
            <td><?= $form->field($model, 'groupIds', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text','readonly'=>true]); ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['name']; ?></th>
            <td><?= $form->field($model, 'name', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:300px','class' => 'input-text']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['cat_id']; ?></th>
            <td style="display: inline-block;width: 206px"><?= $form->field($model, 'cat_id', ['template' => '{input}{error}{hint}'])->widget(\kartik\select2\Select2::className(),['data'=>$cat_tree,'options' => ['placeholder' => '请选择']]) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['group_price']; ?></th>
            <td><?= $form->field($model, 'group_price', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text','readonly'=>true]) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['store']; ?></th>
            <td><?= $form->field($model, 'store', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text','readonly'=>true]); ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['description']; ?></th>
            <td><?= $form->field($model, 'description', ['template' => '{input}{error}{hint}'])->widget(\doumiaoduo\ueditor\Ueditor::className(), ['clientOptions'=>[
                    'serverUrl'=>\common\components\helpers\Fun::url(['/uploader/action']),
                    'toolbars'=>[['fullscreen', 'source', '|', 'undo', 'redo', '|','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript','rowspacingtop', 'rowspacingbottom', 'lineheight', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','simpleupload']],
                    'initialFrameWidth'=>'100%'
                ]]); ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['content']; ?></th>
            <td><?= $form->field($model, 'content', ['template' => '{input}{error}{hint}'])->widget(\doumiaoduo\ueditor\Ueditor::className(), ['clientOptions'=>[
                    'serverUrl'=>\common\components\helpers\Fun::url(['/uploader/action']),
                    'toolbars'=>[['fullscreen', 'source', '|', 'undo', 'redo', '|','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript','rowspacingtop', 'rowspacingbottom', 'lineheight', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','simpleupload']],
                    'initialFrameWidth'=>'100%'
                ]]); ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['max_buy']; ?></th>
            <td><?= $form->field($model, 'max_buy', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text']); ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['score']; ?></th>
            <td><?= $form->field($model, 'score', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text']); ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['store_prompt']; ?></th>
            <td><?= $form->field($model, 'store_prompt', ['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text']); ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['nostore_sell']; ?></th>
            <td><?= $form->field($model, 'nostore_sell', ['template' => '{input}{error}{hint}'])->radioList(['N'=>'否','Y'=>'是'],['style' => 'width:180px', 'class' => 'radiolist']); ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['is_buy']; ?></th>
            <td><?= $form->field($model, 'is_buy', ['template' => '{input}{error}{hint}'])->radioList(['0'=>'否','1'=>'是'],['style' => 'width:180px', 'class' => 'radiolist']); ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['is_show']; ?></th>
            <td><?= $form->field($model, 'is_show', ['template' => '{input}{error}{hint}'])->radioList(['0'=>'否','1'=>'是'],['style' => 'width:180px', 'class' => 'radiolist']); ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['tutor_id']; ?></th>
            <td style="display: inline-block;width: 206px"><?= $form->field($model, 'tutor_id', ['template' => '{input}{error}{hint}'])->widget(\kartik\select2\Select2::className(),['data'=>$tutor,'options' => ['placeholder' => '请选择']]) ?></td>
        </tr>

        <?php //$attribute?>
    </table>
    <div class="m_top_10 btn" style="width:100%">
        <?= Html::submitButton('保存', ['class' => "btn yx-goods-btn yx-radius5", 'id' => 'dosubmit']) ?>&nbsp;
        <a href=<?= Fun::url(['goodsgroup/index','type_id' => 5]) ?>><span class="button">返回</span></a>&nbsp;
    </div>
<?php ActiveForm::end(); ?>
    <?=Html::hiddenInput('arturl',Fun::url('goodsskill/art'))?>
    <?=Html::hiddenInput('viewgroupurl',Fun::url('goodsskill/viewgroup'))?>
</div>
<?php
$js = <<<JS

       $(document).on('change','#artList',function(){
           var val = $(this).val();
           var url = $('input[name="arturl"]').val();
           var viewurl = $('input[name="viewgroupurl"]').val();
           var str = '';
           if(val != ''){
                $.get(url, {id:val}, function (data){
                    $('#main').next().remove();
                       str += '<tr>';
                       str += '<td>'+data.title+'</td>';
                       str += '<td>'+data.cat_name+'</td>';
                       str += '<td>豆苗朵</td>';
                       str += '<td>'+data.max_count+'</td>';
                       str += '<td>'+data.price+'</td>';
                       str += '<td>'+data.class_time+'</td>';
                       str += '<td>'+data.class_count+'</td>';
                       str += '<td><select name="discount_type['+data.id+']" style="width: 120px">';
                       str +='<option value="0">请选择</option>';
                       str +='<option value="1">按比例(%)</option>';
                       str +='<option value="2">固定减额</option>';
                       str +='</select></td>';
                       str +='<td><input type="text" name="price_reduce['+data.id+']" value="0" style="width: 50px"></td>';
                       str +='<td><a class="btn yx-radius2 yx-d-card yx-bg94d5a2" data-url="'+viewurl+'?id='+data.id+'" data-size="1000*600" data-name="查看" rel="dialog-show-iframe" >查看</a></td>';
                       str += '</tr>';
                       $('.tablesaw').append(str);
                       $('#goods-groupids').val(val);
               });
           }
       });

    $(document).on('click','#confirm',function(){
        var price = 0,cost = 0,market_price = 0,store = 0,group_store = 0;

        $("#tablesaw tbody tr").each(function(){

            var goods_price = parseFloat($(this).find('td').eq(4).html());
            var discount_type = $(this).find('select').val();
            var price_reduce = parseFloat($(this).find('input[type="text"]').val());
           // var group_price = 0;
            if(discount_type === '1'){
                var goods_price = goods_price - (goods_price * (price_reduce/100));
            }else if(discount_type === '2'){
                var goods_price = goods_price - price_reduce;
            }
            price = price + parseFloat(goods_price);
        });

        $('.table-form input[id="goods-group_price"]').val(price.toFixed(2));

    });
JS;
$this->registerJS($js);
?>

